#include"declare.h"

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	char choice[5];
	School *first_school = Initlist_school();
	Sport *first_sport = Initlist_sport(); 
	
	//每次开始运行的时候进行文件的读取
	Read_school(first_school);
	Read_sport(first_sport);
	
	while(1)
	{
		//调用主菜单函数
		Main_menu(); 
		//根据用户输入的选择，进行相应的操作 
		printf("请输入您的选择:\n");
		scanf("%s",&choice);
		if(strcmp(choice, "1") == 0)	//录入学校信息
		{
			system("cls");
			//根据用户选择，决定是否继续录入
			char select[2] = "1";
			while(strcmp(select, "1") == 0)
			{
				Input_school(first_school);
				system("cls");
				printf("是否继续录入(1.是  2.否)，请输入您的选择：\n");
				scanf("%s", select);
				system("cls");
			}	
		}
		else if(strcmp(choice, "2") == 0)	//录入体育项目信息
		{
			system("cls");
			Input_sport(first_sport);
			system("pause");
			system("cls");
		}
		else if(strcmp(choice, "3") == 0)	//录入体育项目比赛获奖信息
		{
			system("cls");
			Input_rank(first_sport);
			system("pause");
			system("cls");
		} 
		else if(strcmp(choice, "4") == 0)	//查询学校信息
		{
			system("cls");
			Score(first_school, first_sport);
			int flag = 0;
			while(flag == 0)
			{
				flag = Get_school(first_school);
				system("pause");
				system("cls");	
			}
		} 
		else if(strcmp(choice, "5") == 0)	//查询所有体育项目信息
		{
			system("cls");
			Get_sport(first_sport);
			system("pause");
			system("cls");
		} 
		else if(strcmp(choice, "6") == 0)	//查询学校项目的情况
		{
			system("cls");
			Get_SchoolProjectData(first_school, first_sport);
			system("pause");
			system("cls");
		} 
		else if(strcmp(choice, "7") == 0)	//查询体育项目的比赛结果
		{
			system("cls");
			Get_SportsResult(first_sport);
			system("pause");
			system("cls");
		} 
		else if(strcmp(choice, "8") == 0)	//查询排名信息
		{
			system("cls");
			Score(first_school, first_sport);
			Rank_menu();
			getRankInfo(first_school);
			system("pause");
			system("cls");
		}
		else if(strcmp(choice, "9") == 0)	//修改学校信息
		{
			system("cls");
			Revise_shcool(first_school);
			system("pause");
			system("cls");
		}
		else if(strcmp(choice, "10") == 0)	//修改体育项目信息
		{
			
		}
		else if(strcmp(choice, "11") == 0)	//最终获奖情况
		{
			
		}
		else if(strcmp(choice, "12") == 0)	//退出
		{
			//退出程序时保存信息到文件里
			Save_school(first_school);
			Save_sport(first_sport);
			printf("欢迎下次使用！"); 
			return 1;
		}
		else	//非法输入
		{
			printf("输入有误，请重新输入。\n");
			system("pause");
			system("cls");
		}
	}
	return 0;
}